var isAnyFileUploaded = false;
//$("#someDiv").show();

var UploadedFilesArr = [];
var uploaderFileID = "";
var uploadStatusFromServerResponse = "";
var fileuploadrequest_c = 0;

// $(function() {
//    $("label").click(function() {
//        //  alert("label click");
//        $("#fileselect").click();
//    });
//});

function bytesToSize(bytes, precision) {
    var kilobyte = 1024;
    var megabyte = kilobyte * 1024;
    var gigabyte = megabyte * 1024;
    var terabyte = gigabyte * 1024;

    if ((bytes >= 0) && (bytes < kilobyte)) {
        return bytes + ' bytes';

    } else if ((bytes >= kilobyte) && (bytes < megabyte)) {
        return (bytes / kilobyte).toFixed(precision) + ' KB';

    } else if ((bytes >= megabyte) && (bytes < gigabyte)) {
        return (bytes / megabyte).toFixed(precision) + ' MB';

    } else if ((bytes >= gigabyte) && (bytes < terabyte)) {
        return (bytes / gigabyte).toFixed(precision) + ' GB';

    } else if (bytes >= terabyte) {
        return (bytes / terabyte).toFixed(precision) + ' TB';

    } else {
        return bytes + ' bytes';
    }
}


function expireUserActivity(activityType) {

    if (activityType == "sharing" || activityType == "copy") {
        alert("Session Expired");
        //lightbox_closeCurrent();
        //clearSharingProgress();
    }
    else if (activityType == "download") {
        alert("Session Expired");
//        lightbox_closeCurrent();

    }
    else if (activityType == "uploading") {
        alert("Session Expired");
        //lightbox_closeCurrent();

    }
    window.location.href = window.location;    
    return false;
}


function addUploadProcessingRow(uploadPostId, fid, fname) {
    var isFurtherProced = "true";
    var UPLOAD_MAX_LIMIT = 5242880; //5 mb

    var lirec = "<li id=\"" + fid + "\"></li>";//uploadc-1
    $("#multiformCmntUpload"+uploadPostId).find('#cmntupload_filelist').append(lirec);
    
    //if (UPLOAD_MAX_LIMIT < fileSize) {
//        isFurtherProced = "false";
//        setResponseOnUploadProgress('file_size_too_large)' + "$" + fsize, fid);
//    }
//    else {
//        
//    }
    
    $("#multiformCmntUpload"+uploadPostId).find('#cmntupload_filelist').find("#"+fid).addClass('cmnt-uploading');
    return isFurtherProced;
}

function setResponseOnUploadProgress(response) {

    //console.log(response);
    //alert("setResponseOnUploadProgress: resfor: "+response);
    var jsonRes=$.parseJSON(response);
    //console.log(jsonRes);
    var uploadPostId=jsonRes.postId;
    var responseForID=jsonRes.uploaderID;
    if (jsonRes.errCode<=0) {
        return expireUserActivity("comment_upload_session_timeout");
    }

    if (jsonRes.errCode==200) {
        isAnyFileUploaded = true;
        var FileUploadedSuccess = "File uploaded successfully";
        $("#multiformCmntUpload"+uploadPostId).find('#cmntupload_filelist').find("#"+responseForID).attr("class", "cmnt-upload_done");
        $("#multiformCmntUpload"+uploadPostId).find('#cmntupload_filelist').find("#"+responseForID).html("<img src='"+jsonRes.uploadPath+"' width='120px'/>");
    }
    else {
        $("#multiformCmntUpload"+uploadPostId).find('#cmntupload_filelist').find("#" + responseForID).attr("class", "cmnt-upload_failed");
    }

}

function getCommentsImagesSrc(postid){
    var imgs=$("#multiformCmntUpload"+postid).find('#cmntupload_filelist').find("img");
    var imgSrcs=[];
    if(typeof imgs!==undefined && imgs!="" && imgs.length>0){
        for(var imgcount=0;imgcount<imgs.length;imgcount++){
            imgSrcs.push($(imgs[imgcount]).attr("src"));
        }
    }
    return imgSrcs;
}


function getInternetExplorerVersion()  
// Returns the version of Internet Explorer or a -1
// (indicating the use of another browser).
{
    
    var rv = -1; // Return value assumes failure.
    if (navigator.appName == 'Microsoft Internet Explorer') {
        var ua = navigator.userAgent;
        var re = new RegExp("MSIE ([0-9]{1,}[\.0-9]{0,})");
        if (re.exec(ua) != null)
            rv = parseFloat(RegExp.$1);
    }
    return rv;
}

function A(fileid) {
 
    var oas = new ActiveXObject("Scripting.FileSystemObject");
    var d = document.getElementById(fileid).value;
    var e = oas.getFile(d);
    var f = e.size;
    //alert(f + " bytes");
}

var ver = getInternetExplorerVersion();

